<template>
  <div class="app-container">
    <div class="filter-container">
      <statisSearchBar :start-date="searchForm.startDate" :end-date="searchForm.endDate" :showp-pf-channel="true" @transferFilter="handleFilter" />
    </div>
    <el-table v-loading="listLoading" :data="list" class="mt-10" border>
      <el-table-column label="首充角色等级" prop="level" width="120px" align="center"></el-table-column>
      <el-table-column label="人数" prop="cnt" width="120px" align="center"></el-table-column>
      <el-table-column label="人数占比">
        <template slot-scope="scope">
          <span v-if="sum === 0">0%</span>
          <span v-else>{{ (scope.row.cnt / sum * 100).toFixed(2) }}%</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import StatisSearchBar from '@/components/StatisSearchBar'
import { getRechargeFirst } from '@/api/statis'

export default {
  name: 'RechargeFirst',
  components: { StatisSearchBar },
  data() {
    return {
      list: [],
      headList: [],
      total: 0,
      sum: 0,
      listLoading: false,
      searchForm: {
        startDate: new Date(),
        endDate: new Date()
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleFilter(query) {
      this.searchForm = query
      this.getList()
    },
    async getList() {
      this.listLoading = true
      const res = await getRechargeFirst(this.searchForm)
      this.listLoading = false
      this.list = res.data.items
      this.total = res.data.total
      this.sum = res.data.total_account
    }
  }
}
</script>
